﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfStudy
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();          
        }

        private void Start(object sender, RoutedEventArgs e)
        {
            /* // TB.Text = String.Concat((Int32.Parse(TB.Text)+1));
             //TB.Text = @"Joe said ""Hello"" to me";
             //多维数组
             int[,] numbers = new int[3, 3] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
             //TB.Text = outputArrary(numbers);
             //交叉数组(第一个数组的大小必须指定)
             int[][][] aaNumbers = new int[2][][] { 
                 new int[][] { 
                     new int[2] { 1,2 }, 
                     new int[2] { 3,4 } }, 
                 new int[][] { 
                     new int[2] { 5, 6 },
                     new int[2] { 7, 8 } } };
             Console.WriteLine(aaNumbers[1][1][1]);

             Person p1 = new Person() { Age = 12, Name = "不屈白银" };
             TB.Text = p1.ToString();*/

            Person p = this.FindResource("person") as Person;
            MessageBox.Show(p.Age.ToString());
        }

        private string outputArrary(int [,] arr)
        {
            Console.WriteLine(arr.IsFixedSize);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 3; i++)
            {
                sb.Append("[");
                for (int j = 0; j < 3; j++)
                {
                    sb.Append(arr[i, j]+",");
                }
                sb.Remove(sb.Length - 1, 1);
                sb.Append("]\r");
            }
            return sb.ToString();
        }
    }

    class Person
    {

        private string name;


        public string Name
        {
            get { return name; }
            set
            {
                if (value.Equals("荣耀王者"))
                {
                    this.name = "铁five";
                }
                else
                {
                    this.name = value;
                }
            }
        }
        [TypeConverter(typeof(StringToPersonTypeConvert))]
        public Person Child { get; set; }

        public int Age { get; set; }

        public override string ToString()
        {
            return String.Format("姓名：{0}，年龄：{1}", Age, name);
        }
    }

    public class StringToPersonTypeConvert:TypeConverter
    {
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value is string)
            {
                Person p = new Person() { Name = value as string, Age = 0 };
                return p;
            }
            return base.ConvertFrom(context, culture, value);
        }
    }
}
